package com.egao.go.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.go.entity.Dutch;
import com.egao.go.entity.DutchUser;
import com.egao.go.service.DutchService;
import com.egao.go.service.DutchUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 *
 * 群AA
 * @author : Doman
 * @date : 2020-09-21 10:28:24
 * @version ：1.0
 */

@Api(tags = "群AANt")
@RestController
@RequestMapping("/api/nt/go/dutch")
public class DutchNTController extends BaseController {

	@Autowired
	private DutchService dutchService;
    @Autowired
    private DutchUserService dutchUserService;

	/**
	 * 分页查询列表
	 */
//    @OperLog(value = "群AA", desc = "分页查询")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, Dutch dutch) throws Exception{
        return dutchService.list(page, dutch, getLoginUser());
    }

    /**
     * 查询全部群AA
     */
//    @OperLog(value = "群AA", desc = "查询全部")
    @PostMapping("/list")
    public JsonResult list(Dutch dutch){
        return dutchService.list(dutch, getLoginUser());
    }

    /**
     * 查询全部报名人
     */
    @ApiOperation("查询全部报名人")
    @PostMapping("/dutchUserList")
    public JsonResult list(DutchUser dutchUser){
        return dutchUserService.list(dutchUser, new User(1));
    }

    /**
     * 根据id查询群AA
     */
//    @OperLog(value = "群AA", desc = "根据id查询")
    @PostMapping("/get")
    public JsonResult get(Dutch dutch) {
        return dutchService.getById(dutch);
		// 使用关联查询
        //PageParam<dutch> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<dutch> records = dutchService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加群AA
     */
    @OperLog(value = "群AA", desc = "添加", param = false, result = true)
    @ApiOperation("添加群AA")
    @PostMapping("/save")
    public JsonResult save(Model model, Dutch dutch) {
        return dutchService.save(dutch, getLoginUser());
    }

    /**
     * 修改群AA
     */
    @OperLog(value = "群AA", desc = "修改", param = false, result = true)
    @ApiOperation("修改群AA")
    @PostMapping("/update")
    public JsonResult update(Model model, Dutch dutch) {
        return dutchService.update(dutch, getLoginUser());
    }

    /**
     * 修改群AA
     */
    @OperLog(value = "群AA", desc = "修改", param = false, result = true)
    @ApiOperation("修改群AA状态 状态: 报名中,开始结算,完成")
    @PostMapping("/updateState")
    public JsonResult updateState(Model model, Dutch dutch) {
        return dutchService.updateState(dutch, getLoginUser());
    }

    /**
     * 删除群AA
     */
    @OperLog(value = "群AA", desc = "删除", result = true)
    @ApiOperation("删除群AA")
    @PostMapping("/remove")
    public JsonResult remove(Dutch dutch ) {
        return dutchService.remove(dutch, getLoginUser());
    }

}
